package createTreeByString;

import java.util.Scanner;


public class Main {
    static class TreeNode {
        private char val;
        private TreeNode left;
        private TreeNode right;
        public TreeNode() {
        }
        public TreeNode(char val) {
            this.val = val;
        }

    }
    private static int i = 0;
    //以先序遍历创建二叉树
    public  static TreeNode create(String str) {
        TreeNode root = null;
        if (str.charAt(i) != '#') {
            root = new TreeNode(str.charAt(i));
            i++;
            root.left = create(str);
            root.right = create(str);
        } else {
            i++;
        }
        return root;
    }
    //中序遍历
    public static void inOrder(TreeNode root){
        if(root == null) return;
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }
    public static void main(String[] args) {
        Scanner in  = new Scanner(System.in);
        String str ;
        while (in.hasNextLine()) {
            str = in.next();
            TreeNode root = create(str);
            inOrder(root);
        }
    }
}
